home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWTPtrSlist.z / RWTPtrSlist
Encoding:
Text File  |  2002-10-03  |  19.9 KB  |  529 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTPtrSlist<T> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/tpslist.h>
  13.  
  14.  
  15.  
  16.               RWTPtrSlist<T> list;
  17.  
  18. PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!!
  19.      IIIIffff yyyyoooouuuu ddddoooo nnnnooootttt hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd
  20.      hhhheeeerrrreeee....  OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt described in the Class
  21.      Reference.
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  29.      This class maintains a collection of pointers to type TTTT, implemented as a
  30.      singly-linked list.  This is a ppppooooiiiinnnntttteeeerrrr based list: pointers to objects
  31.      are copied in and out of the links that make up the list. Parameter TTTT
  32.      represents the type of object to be inserted into the list, either a
  33.      class or fundamental type.  The class TTTT must have:
  34.           well-defined equality semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr========((((ccccoooonnnnsssstttt TTTT&&&&))))).
  35.  
  36.  
  37. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  38.      Isomorphic
  39.  
  40. EEEExxxxaaaammmmpppplllleeee
  41.      In this example, a singly-linked list of RRRRWWWWDDDDaaaatttteeeessss is exercised.
  42.  
  43.               #include <rw/tpslist.h>
  44.           #include <rw/rwdate.h>
  45.           #include <rw/rstream.h>
  46.           main()  {
  47.             RWTPtrSlist<RWDate> dates;
  48.             dates.insert(new RWDate(2, "June", 52));        // 6/2/52
  49.             dates.insert(new RWDate(30, "March", 46));      // 3/30/46
  50.             dates.insert(new RWDate(1, "April", 90));       // 4/1/90
  51.             // Now look for one of the dates:
  52.             RWDate key(2, "June", 52);
  53.             RWDate* d = dates.find(&key);
  54.             if (d){
  55.               cout << "Found date " << *d << endl;
  56.             }
  57.             // Remove in reverse order:
  58.             while (!dates.isEmpty()){
  59.               d = dates.removeLast();
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.               cout << *d << endl;
  75.               delete d;
  76.             }
  77.             return 0;
  78.           }
  79.  
  80.  
  81.      Program output:
  82.  
  83.               Found date June 2, 1952
  84.           April 1, 1990
  85.           March 30, 1946
  86.           June 2, 1952
  87.  
  88. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  89.               RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt<T>();
  90.  
  91.  
  92.      Construct an empty list.
  93.  
  94.               RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt<T>(const RWTPtrSlist<T>& c);
  95.  
  96.  
  97.      Constructs a new singly-linked list as a shallow copy of cccc.  After
  98.      construction, pointers will be shared between the two collections.
  99.  
  100. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss
  101.               RWTPtrSlist&
  102.           ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrSlist<T>& c);
  103.  
  104.  
  105.      Sets self to a shallow copy of cccc.  Afterwards, pointers will be shared
  106.      between the two collections.
  107.  
  108.               T*&
  109.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i);
  110.           T* const&
  111.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const;
  112.  
  113.  
  114.      Returns a pointer to the iiiith value in the list.  The first variant can be
  115.      used as an llllvvvvaaaalllluuuueeee, the second cannot.  The index iiii must be between zero
  116.      and the number of items in the collection less one, or an exception of
  117.      type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown.
  118.  
  119. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  120.               void
  121.           aaaappppppppeeeennnndddd(T* a);
  122.  
  123.  
  124.      Appends the item pointed to by aaaa to the end of the list.
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.               void
  141.           aaaappppppppllllyyyy(void (*applyFun)(T*, void*), void* d);
  142.  
  143.  
  144.      Applies the user-defined function pointed to by aaaappppppppllllyyyyFFFFuuuunnnn to every item in
  145.      the list.  This function must have the prototype:
  146.  
  147.               void yyyyoooouuuurrrrFFFFuuuunnnn(T* a, void* d);
  148.  
  149.  
  150.  
  151.  
  152.  
  153.      This function will be called for each item in the list, with a pointer to
  154.      the item as the first argument.  Client data may be passed through as
  155.      parameter dddd.
  156.  
  157.               T*&
  158.           aaaatttt(size_t i);
  159.           T* const;
  160.           aaaatttt(size_t i) const;
  161.  
  162.  
  163.      Returns a pointer to the iiiith value in the list.  The first variant can be
  164.      used as an llllvvvvaaaalllluuuueeee, the second cannot.  The index iiii must be between zero
  165.      and the number of items in the collection less one, or an exception of
  166.      type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown.
  167.  
  168.               void
  169.           cccclllleeeeaaaarrrr();
  170.  
  171.  
  172.      Removes all items from the collection.
  173.  
  174.               void
  175.           cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy();
  176.  
  177.  
  178.      Removes all items from the collection aaaannnndddd deletes them.
  179.  
  180.               RWBoolean
  181.           ccccoooonnnnttttaaaaiiiinnnnssss(const T* a) const;
  182.  
  183.  
  184.      Returns TTTTRRRRUUUUEEEE if the list contains an object that is equal to the object
  185.      pointed to by aaaa, FFFFAAAALLLLSSSSEEEE otherwise.  Equality is measured by the class-
  186.      defined equality operator for type TTTT.
  187.  
  188.               RWBoolean
  189.           ccccoooonnnnttttaaaaiiiinnnnssss(RWBoolean (*testFun)(T*, void*),void* d) const;
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      Returns TTTTRRRRUUUUEEEE if the list contains an item for which the user-defined
  207.      "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE .  Returns FFFFAAAALLLLSSSSEEEE
  208.      otherwise.  The tester function must have the prototype:
  209.  
  210.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  211.  
  212.  
  213.  
  214.  
  215.  
  216.      This function will be called for each item in the list, with a pointer to
  217.      the item as the first argument.  Client data may be passed through as
  218.      parameter dddd.
  219.  
  220.               size_t
  221.           eeeennnnttttrrrriiiieeeessss() const;
  222.  
  223.  
  224.      Returns the number of items that are currently in the collection.
  225.  
  226.               T*
  227.           ffffiiiinnnndddd(const T* target) const;
  228.  
  229.  
  230.      Returns a pointer to the first object encountered which is equal to the
  231.      object pointed to by ttttaaaarrrrggggeeeetttt, or nnnniiiillll if no such object can be found.
  232.      Equality is measured by the class-defined equality operator for type TTTT.
  233.  
  234.               T*
  235.           ffffiiiinnnndddd(RWBoolean (*testFun)(T*, void*),void* d,) const;
  236.  
  237.  
  238.      Returns a pointer to the first object encountered for which the user-
  239.      defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or nnnniiiillll if no
  240.      such object can be found.  The tester function must have the prototype:
  241.  
  242.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  243.  
  244.  
  245.  
  246.  
  247.  
  248.      This function will be called for each item in the list, with a pointer to
  249.      the item as the first argument.  Client data may be passed through as
  250.      parameter dddd.
  251.  
  252.               T*&
  253.           ffffiiiirrrrsssstttt();
  254.           T* const&
  255.           ffffiiiirrrrsssstttt() const;
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.      Returns a pointer to the first item in the list.  The behavior is
  273.      undefined if the list is empty.
  274.  
  275.               T*
  276.           ggggeeeetttt();
  277.  
  278.  
  279.      Returns a pointer to the first item in the list and removes the item.
  280.      The behavior is undefined if the list is empty.
  281.  
  282.               size_t
  283.           iiiinnnnddddeeeexxxx(const T* a);
  284.  
  285.  
  286.      Returns the index of the first object that is equal to the object pointed
  287.      to by aaaa, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such object.  Equality is measured by
  288.      the class-defined equality operator for type TTTT.
  289.  
  290.               size_t
  291.           iiiinnnnddddeeeexxxx(RWBoolean (*testFun)(T*, void*),void* d) const;
  292.  
  293.  
  294.      Returns the index of the first object for which the user-defined tester
  295.      function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no
  296.      such object.  The tester function must have the prototype:
  297.  
  298.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  299.  
  300.  
  301.  
  302.  
  303.  
  304.      This function will be called for each item in the list, with a pointer to
  305.      the item as the first argument.  Client data may be passed through as
  306.      parameter dddd.
  307.  
  308.               void
  309.           iiiinnnnsssseeeerrrrtttt(T* a);
  310.  
  311.  
  312.      Adds the object pointed to by aaaa to the end of the list.
  313.  
  314.               void
  315.           iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, T* a);
  316.  
  317.  
  318.      Adds the object pointed to by aaaa at the index position iiii.  This position
  319.      must be between zero and the number of items in the list, or an exception
  320.      of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown.
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               RWBoolean
  339.           iiiissssEEEEmmmmppppttttyyyy() const;
  340.  
  341.  
  342.      Returns TTTTRRRRUUUUEEEE if there are no items in the list, FFFFAAAALLLLSSSSEEEE otherwise.
  343.  
  344.               T*&
  345.           llllaaaasssstttt();
  346.           T* const&
  347.           llllaaaasssstttt() const;
  348.  
  349.  
  350.      Returns a pointer to the last item in the list.  The behavior is
  351.      undefined if the list is empty.
  352.  
  353.               size_t
  354.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T* a) const;
  355.  
  356.  
  357.      Returns the number of objects in the list that are equal to the object
  358.      pointed to by aaaa.  Equality is measured by the class-defined equality
  359.      operator for type TTTT.
  360.  
  361.               size_t
  362.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(RWBoolean (*testFun)(T*, void*),void* d)
  363.                         const;
  364.  
  365.  
  366.      Returns the number of objects in the list for which the user-defined
  367.      "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE .  The tester
  368.      function must have the prototype:
  369.  
  370.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  371.  
  372.  
  373.  
  374.  
  375.  
  376.      This function will be called for each item in the list, with a pointer to
  377.      the item as the first argument.  Client data may be passed through as
  378.      parameter dddd.
  379.  
  380.               void
  381.           pppprrrreeeeppppeeeennnndddd(T* a);
  382.  
  383.  
  384.      Adds the item pointed to by aaaa to the beginning of the list.
  385.  
  386.               T*
  387.           rrrreeeemmmmoooovvvveeee(const T* a);
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.      Removes the first object which is equal to the object pointed to by aaaa and
  405.      returns a pointer to it, or nnnniiiillll if no such object could be found.
  406.      Equality is measured by the class-defined equality operator for type TTTT.
  407.  
  408.               T*
  409.           rrrreeeemmmmoooovvvveeee(RWBoolean (*testFun)(T*, void*),void* d);
  410.  
  411.  
  412.      Removes the first object for which the user-defined tester function
  413.      pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE and returns a pointer to it, or nnnniiiillll if
  414.      there is no such object.  The tester function must have the prototype:
  415.  
  416.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  417.  
  418.  
  419.  
  420.  
  421.  
  422.      This function will be called for each item in the list, with a pointer to
  423.      the item as the first argument.  Client data may be passed through as
  424.      parameter dddd.
  425.  
  426.               size_t
  427.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T* a);
  428.  
  429.  
  430.      Removes all objects which are equal to the object pointed to by aaaa.
  431.      Returns the number of objects removed.  Equality is measured by the
  432.      class-defined equality operator for type TTTT.
  433.  
  434.               size_t
  435.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(RWBoolean (*testFun)(T*, void*),void* d);
  436.  
  437.  
  438.      Removes all objects for which the user-defined tester function pointed to
  439.      by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE.  Returns the number of objects removed.  The
  440.      tester function must have the prototype:
  441.  
  442.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  443.  
  444.  
  445.  
  446.  
  447.  
  448.      This function will be called for each item in the list, with a pointer to
  449.      the item as the first argument.  Client data may be passed through as
  450.      parameter dddd.
  451.  
  452.               T*
  453.           rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i);
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  467.  
  468.  
  469.  
  470.      Removes the object at index iiii and returns a pointer to it.  An exception
  471.      of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if iiii is not a valid index.  Valid
  472.      indices are from zero to the number of items in the list less one.
  473.  
  474.               T*
  475.           rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt();
  476.  
  477.  
  478.      Removes the first item in the list and returns a pointer to it.  The
  479.      behavior is undefined if the list is empty.
  480.  
  481.               T*
  482.           rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt();
  483.  
  484.  
  485.      Removes the last item in the list and returns a pointer to it.  The
  486.      behavior is undefined if the list is empty.  This function is relatively
  487.      slow because removing the last link in a singly-linked list necessitates
  488.      access to the next-to-the-last link, requiring that the whole list be
  489.      searched.
  490.  
  491. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss
  492.               RWvostream&
  493.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrSlist<T>& coll);
  494.           RWFile&
  495.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrSlist<T>& coll);
  496.  
  497.  
  498.      Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to
  499.      it if it has already been saved.
  500.  
  501.               RWvistream&
  502.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrSlist<T>& coll);
  503.           RWFile&
  504.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrSlist<T>& coll);
  505.  
  506.  
  507.      Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm.
  508.  
  509.               RWvistream&
  510.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrSlist<T>*& p);
  511.           RWFile&
  512.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrSlist<T>*& p);
  513.  
  514.  
  515.      Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a
  516.      new collection off the heap and sets pppp to point to it, or sets pppp to point
  517.      to a previously read instance.  If a collection is created off the heap,
  518.      then you are responsible for deleting it.
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.